﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.Windows.Forms;

namespace KornyezetVedelem
{
    class Szallitok_Prog : DAL
    {
        private DataSet dS;
        private String str;
        public Szallitok_Prog(ref bool Err)
        {
            if (!base.IsConnectCreated()) //ha a kapcsolat meg nem jott letre(meg nincs letrehozva)
            {
                Err = !base.MakeConnection();
            }
        }


        //feltolti a DataReader objektumot a Nyaralok tabla NyaraloNev oszlopok mezoivel
        public System.Data.SqlClient.SqlDataReader SzallitokToltDR(ref string ErrM)
        {
            string sSQL = "SELECT * FROM Szallitok";
            myDataReader = base.myExecuteReader(sSQL, ref ErrM);
            return myDataReader;
        }
        public DataSet SzallitokToltDS(ref string ErrM)
        {
            string sSQL = "SELECT * FROM Szallitok";
            dS = base.myExecuteReader_D(sSQL, ref ErrM);
            return dS;
        }
        public void Beszur(String Nev)
        {
           // string sSQL = "SELECT MAX(SzallitoId) FROM Szallitok";
           // int max = base.getMaximumId(sSQL) + 1;
           // sSQL = "INSERT INTO Szallitok values(" + max + "," + "'" + Nev + "'" + ")";
            String sSQL = "exec proc_1 '" + Nev + "'";
            beszuras(sSQL);
        }
        public Exception Torol(String Id)
        {
            Exception ex1;
           // String delSQL = "DELETE FROM Szallitok WHERE SzallitoId = " + Id;
            String delSQL = "exec proc_2 " + Id;
            //String delSQL = "exec torol_mindent";
            ex1 = Torles(delSQL);
            return ex1;

        }
        public void Modosit(String Id, String Nev)
        {
            String sSQL = "Update Szallitok Set SzallitokNeve = '" + Nev + "'" + "Where SzallitoID = " + Id;
            modositas(sSQL);
        }
        public void feltoltListBox(ListBox l)
        {
            MakeConnection();
            string sSQL = "SELECT Cim from AtrakoAllomas";
            System.Data.SqlClient.SqlDataReader reader = base.myExecuteReader(sSQL, ref str);
            while (reader.Read())
            {
                l.Items.Add(reader["Cim"]);
            }
            reader.Close();
            CloseConnection();
        }
        public DataSet Szuro(String s1,String s2,int ora)
        {
            MakeConnection();
            string sSQL = "SELECT distinct sz.SzallitoId,sz.SzallitokNeve FROM Szallitok sz";

            if (s1 != "" && s2 != "")
            {
                sSQL = sSQL + ",IdeiglenesLerakatok i, AtrakoAllomas a,Szallit szal Where sz.szallitoid = szal.szallitoid and a.atrakoallomasid = szal.atrakoallomasid and szal.ideigleneslerakatokid = i.ideigleneslerakatokid and i.Nev='" + s1 + "' and a.Cim = '" + s2 + "'";
                if (ora != -1)
                    sSQL = sSQL + " and szal.Ora =" + ora;
            }
            else
                if (ora != -1)
                    sSQL = sSQL + ",IdeiglenesLerakatok i, AtrakoAllomas a,Szallit szal Where sz.szallitoid = szal.szallitoid and a.atrakoallomasid = szal.atrakoallomasid and szal.ideigleneslerakatokid = i.ideigleneslerakatokid and szal.Ora = " + ora;
            dS = base.myExecuteReader_D(sSQL, ref str);
            CloseConnection();
            return dS;
        }
    }
}